package com.duan.laugh.common.mybatisplus.config;

import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
import com.duan.laugh.common.security.util.UserUtils;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.LongValue;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 租户配置
 *
 * @author duanjw
 */
public class LaughTenantHandler implements TenantHandler {
    @Autowired
    private TenantConfigProperties properties;

    @Override
    public Expression getTenantId() {
        return new LongValue(UserUtils.getUser().getTenantId());
    }

    @Override
    public String getTenantIdColumn() {
        return properties.getColumn();
    }

    @Override
    public boolean doTableFilter(String tableName) {
        return properties.getIgnoreTables().contains(tableName);
    }
}
